<?php
namespace app\admin\model;

use \think\Config;
use \think\Model;
use \think\Session;


/**
 *
 *
 * @author chengbin
 */
class Attachment extends Admin
{
    public function getList($request)
    {
        $request = $this->fmtRequest( $request );
        return $this->where($request['map'])->limit($request['offset'], $request['limit'])->order('id','DESC')->select();
    }

    public function getStatusAttr($value)
    {
        // $status = self::getAllStatus();
        // return $status[$value];
    }

    public function saveData($data)
    {
        if(!isset($data['sort'])) {
            $data['sort'] = 99;
        }
        $data['create_datetime'] = date('Y-m-d H:i:s',time());
        if(isset($data['id']) && $data['id']){
            $this->where(['id'=>$data['id']])->update($data);
        }else{
            $this->insert($data);
        }
    }



    public function deleteById($id)
    {
        $result = self::destroy($id);
        if ($result > 0) {
            return info(lang('Delete succeed'), 1);
        }
    }



    private function _fmtTitle( $parent_rule_val )
    {
        $ex_tmp = explode('/', $parent_rule_val);
        $title = '';
        if(!empty($ex_tmp)) {
            foreach($ex_tmp as $val) {
                $tmp[] = ucwords($val);
            }
            $title = implode('/', $tmp);
            unset($tmp);
        }
        unset($ex_tmp);
        return $title;
    }


}
